<?php
require_once("includes/include.php");
?>
<?php
$post = $_POST;
$menu = $post['menu'];
switch ($menu){
	case 'blog':blogSearch($post['key']);break;
	case 'blogDetail':getBlogDetail($post['blogId']);break;
}
function blogSearch($keys){
	if (!$keys){
		return false;
	}else if (strrchr($keys," ")){
		$keys = explode(" ",$keys);
	}
	$dao = new searchdao();
	$searchResult = $dao->blogSearch($keys);
	$html='';
	$totalItem = count($searchResult);
	$html.="共搜索到<strong>".$totalItem."</strong>条&nbsp;&nbsp;<span style='float:right;color:green;'>双击查看详细内容</span><br /><hr />";
	foreach ($searchResult as $key=>$item){
		$listNumber = $key+1;
		$content=getBlogShortCut($item['content']);
		$html.="<div id=\"blogId{$item['id']}\" class='blogiterm'>";
		$html.="<h2><strong>$listNumber</strong>、<img src='style/fam_page_white.gif' /> <a href='bloglist.php?blogId={$item['id']}' target='_blank'>".$item["title"]."</a></h2>";
		$html.="<div class='blogtime'>".$item['postTime']."</div>";
		$html.="<div class='blogtext'>$content</div>";
		$html.="</div>";
	}
	echo $html;
}
function getBlogShortCut($str,$len=600){
	//$str ="<p><h3>dsfdsf</h3></p>";
	$pattern = "/(<[^>]+>)|(<[\/?][^>]+>)/i";
	$replaceStr = "";
	$str = preg_replace($pattern,$replaceStr,$str);
	$str = substr($str,0,$len)."......";
	$str ="<p class='blogShortCutP'>$str</p>";
	return $str;
}
function getBlogDetail($blogId){
	$dao = new searchdao();
	$blogDetail = $dao->getBlogDetail($blogId);
	foreach ($blogDetail as $detail):
		echo $detail['content'];
	endforeach;
}
?>